package router

import (
	"duoke/controller/admin"
	"duoke/controller/admin/adminYoga"
	"duoke/middleware"
	"duoke/utils/gstr"
	"duoke/utils/yaml"
	"github.com/gin-gonic/gin"
	"github.com/gogf/gf/v2/frame/g"
	"net/http/httputil"
	"net/url"
)

func LoadAdmin(r *gin.Engine) {
	config := yaml.GetConfig()
	// 反向代理
	r.Any("admin/v2/*any", func(c *gin.Context) {
		target := "http://127.0.0.1:" + config.Work.Port //转向的host
		remote, err := url.Parse(target)
		if err != nil {
			g.Dump("反向代理错误", err)
		}
		proxy := httputil.NewSingleHostReverseProxy(remote)
		c.Request.URL.Path = gstr.Replace(c.Request.URL.Path, "admin/v2", "admin")
		proxy.ServeHTTP(c.Writer, c.Request)
	})
	/**
	 * 后台管理
	 */
	r.GET("/", admin.Index.Index)
	r.GET("tables/del", admin.Index.TruncateTable)
	adminRouter := r.Group("admin")
	{
		adminRouter.Any("test", admin.Test.Index)
		adminRouter.Use(middleware.AccountAuth())
		// 授权验证
		// adminRouter.Use(middleware.Authorize())
		// 门店
		adminRouter.POST("store/list", admin.Store.List)
		adminRouter.POST("store/save", admin.Store.Save)
		adminRouter.POST("store/del", admin.Store.Del)
		// 商品
		adminRouter.POST("goods/info", admin.Goods.Info)
		adminRouter.POST("goods/list", admin.Goods.List)
		adminRouter.POST("goods/save", admin.Goods.Save)
		adminRouter.POST("goods/copy", admin.Goods.Copy)
		adminRouter.POST("goods/del", admin.Goods.Del)
		adminRouter.POST("goods/state", admin.Goods.State)
		// 设置
		adminRouter.POST("setting/info", admin.Setting.Info)
		adminRouter.POST("setting/save", admin.Setting.Save)
		// 账户设置
		adminRouter.POST("account_setting/info", admin.AccountSetting.Info)
		adminRouter.POST("account_setting/save", admin.AccountSetting.Save)
		adminRouter.POST("account_setting/upload_minicode", admin.AccountSetting.UploadMinicode)
		// 分账账号设置
		adminRouter.POST("separate_accounts/list", admin.SeparateAccounts.List)
		adminRouter.POST("separate_accounts/save", admin.SeparateAccounts.Save)
		adminRouter.POST("separate_accounts/del", admin.SeparateAccounts.Del)

		// 分账子账号设置
		adminRouter.POST("separate_accounts_sub/list", admin.SeparateAccountsSub.List)
		adminRouter.POST("separate_accounts_sub/save", admin.SeparateAccountsSub.Save)
		adminRouter.POST("separate_accounts_sub/del", admin.SeparateAccountsSub.Del)

		// 分账组
		adminRouter.POST("separate_group/save", admin.SeparateGroup.Save)
		adminRouter.POST("separate_group/list", admin.SeparateGroup.List)
		adminRouter.POST("separate_group/del", admin.SeparateGroup.Del)

		// 用户
		adminRouter.POST("user/all", admin.User.All)
		adminRouter.POST("user/list", admin.User.List)
		adminRouter.POST("user/save", admin.User.Save)
		adminRouter.POST("user/set", admin.User.Set)
		adminRouter.POST("user/del", admin.User.Del)
		adminRouter.POST("user/tixian", admin.User.Tixian)
		adminRouter.POST("user/recharge_balance", admin.User.RechargeBalance)
		adminRouter.POST("user/withdrawal_list", admin.User.WithdrawalList)
		adminRouter.POST("user/withdrawal_save", admin.User.WithdrawalSave)

		// 机器人
		adminRouter.POST("robot/list", admin.Robot.List)
		adminRouter.POST("robot/save", admin.Robot.Save)
		adminRouter.POST("robot/del", admin.Robot.Del)
		// 员工
		adminRouter.POST("staff/list", admin.Staff.List)
		// 订单和团
		adminRouter.POST("order/list", admin.Order.List)
		adminRouter.POST("order/page", admin.Order.Page)
		adminRouter.POST("group/list", admin.Group.List)
		adminRouter.POST("group/page", admin.Group.Page)
		adminRouter.POST("order/refund", admin.Order.Refund)
		// 奖励
		adminRouter.POST("reward/list", admin.Reward.List)
		adminRouter.POST("reward/send", admin.Reward.Send)
		// 工作台
		adminRouter.POST("dashboard/count", admin.Dashboard.Count)
		adminRouter.POST("dashboard/everyday", admin.Dashboard.Everyday)
		adminRouter.POST("dashboard/hot_goods", admin.Dashboard.HotGoods)
		// 商品账户
		adminRouter.POST("goods_account/list", admin.GoodsAccount.List)
		adminRouter.POST("goods_account/del", admin.GoodsAccount.Del)
		adminRouter.POST("goods_account/save", admin.GoodsAccount.Save)
		adminRouter.POST("goods_account/state", admin.GoodsAccount.State)
		// 团操作
		adminRouter.POST("group/rise", admin.Group.Rise)
		adminRouter.POST("group/drop", admin.Group.Drop)
		adminRouter.POST("group/set_head", admin.Group.SetHead)
		adminRouter.POST("group/change", admin.Group.Change)
		adminRouter.POST("group/add_robot", admin.Group.AddRobot)
		adminRouter.POST("group/ranking_version", admin.Group.RankingVersion)

		// 卡券
		adminRouter.POST("coupon/merchant_refund", admin.Coupon.MerchantRefund)
		adminRouter.POST("coupon/user_refund", admin.Coupon.UserRefund)

		// 分账订单
		adminRouter.POST("share_order/list", admin.ShareOrder.List)
		adminRouter.POST("share_order/del", admin.ShareOrder.Del)
		adminRouter.POST("share_order/retransmission", admin.ShareOrder.Retransmission)

		// 收费视频菜单
		adminRouter.POST("course_menu/list", admin.CourseMenu.List)
		adminRouter.POST("course_menu/save", admin.CourseMenu.Save)
		adminRouter.POST("course_menu/del", admin.CourseMenu.Del)
		adminRouter.POST("course_menu/wx_menu", admin.CourseMenu.WxMenu)

		adminRouter.POST("statistics/course", admin.Statistics.Course)
		adminRouter.POST("statistics/course_list", admin.Statistics.CourseList)

		// 教书资源
		adminRouter.POST("course_lecturer/list", admin.CourseLecturer.List)
		adminRouter.POST("course_lecturer/save", admin.CourseLecturer.Save)
		adminRouter.POST("course_lecturer/del", admin.CourseLecturer.Del)
		// 教学目录
		adminRouter.POST("course_video/save", admin.CourseVideo.Save)
		adminRouter.POST("course_video/list", admin.CourseVideo.List)
		adminRouter.POST("course_video/del", admin.CourseVideo.Del)

		// 教学列表
		adminRouter.POST("course_list/save", admin.CourseList.Save)
		adminRouter.POST("course_list/list", admin.CourseList.List)
		adminRouter.POST("course_list/del", admin.CourseList.Del)

		// 首页menu
		adminRouter.POST("home_menu/list", admin.HomeMenu.List)
		adminRouter.POST("home_menu/save", admin.HomeMenu.Save)
		adminRouter.POST("home_menu/del", admin.HomeMenu.Del)

		// 首页banner
		adminRouter.POST("home_banner/list", admin.HomeBanner.List)
		adminRouter.POST("home_banner/save", admin.HomeBanner.Save)
		adminRouter.POST("home_banner/del", admin.HomeBanner.Del)

		// 首页公告
		adminRouter.POST("home_notice/list", admin.HomeNotice.List)
		adminRouter.POST("home_notice/save", admin.HomeNotice.Save)
		adminRouter.POST("home_notice/del", admin.HomeNotice.Del)

		// 首页视频
		adminRouter.POST("home_video/list", admin.HomeVideo.List)
		adminRouter.POST("home_video/save", admin.HomeVideo.Save)
		adminRouter.POST("home_video/del", admin.HomeVideo.Del)

		// 首页图文内容
		adminRouter.POST("home_content/list", admin.HomeContent.List)
		adminRouter.POST("home_content/save", admin.HomeContent.Save)
		adminRouter.POST("home_content/del", admin.HomeContent.Del)

		// 瑜伽小程序

		// 瑜伽小程序-教师
		adminRouter.POST("teacher/save", adminYoga.Teacher.Save)
		adminRouter.POST("teacher/list", adminYoga.Teacher.List)
		adminRouter.POST("teacher/info", adminYoga.Teacher.Info)
		adminRouter.POST("teacher/del", adminYoga.Teacher.Del)

		// 瑜伽小程序-场馆
		adminRouter.POST("venue/save", adminYoga.Venue.Save)
		adminRouter.POST("venue/list", adminYoga.Venue.List)
		adminRouter.POST("venue/info", adminYoga.Venue.Info)
		adminRouter.POST("venue/del", adminYoga.Venue.Del)

		// 瑜伽小程序-课程
		adminRouter.POST("group_class/save", adminYoga.GroupClass.Save)
		adminRouter.POST("group_class/list", adminYoga.GroupClass.List)
		adminRouter.POST("group_class/info", adminYoga.GroupClass.Info)
		adminRouter.POST("group_class/del", adminYoga.GroupClass.Del)

		// 瑜伽小程序-日期
		adminRouter.POST("date/save", adminYoga.Date.Save)
		adminRouter.POST("date/list", adminYoga.Date.List)
		adminRouter.POST("date/info", adminYoga.Date.Info)
		adminRouter.POST("date/del", adminYoga.Date.Del)

		// 瑜伽小程序-日期v2
		adminRouter.POST("school_timetable/save", adminYoga.SchoolTimetable.Save)
		adminRouter.POST("school_timetable/list", adminYoga.SchoolTimetable.List)
		adminRouter.POST("school_timetable/info", adminYoga.SchoolTimetable.Info)
		adminRouter.POST("school_timetable/del", adminYoga.SchoolTimetable.Del)

		// 瑜伽小程序-公告
		adminRouter.POST("notice/save", adminYoga.Notice.Save)
		adminRouter.POST("notice/list", adminYoga.Notice.List)
		adminRouter.POST("notice/info", adminYoga.Notice.Info)
		adminRouter.POST("notice/del", adminYoga.Notice.Del)

		// 瑜伽小程序-相册
		adminRouter.POST("album/save", adminYoga.Album.Save)
		adminRouter.POST("album/list", adminYoga.Album.List)
		adminRouter.POST("album/info", adminYoga.Album.Info)
		adminRouter.POST("album/del", adminYoga.Album.Del)
		adminRouter.POST("album/search", adminYoga.Album.Search)

		// 瑜伽小程序-班课
		adminRouter.POST("course/save", adminYoga.Course.Save)
		adminRouter.POST("course/list", adminYoga.Course.List)
		adminRouter.POST("course/info", adminYoga.Course.Info)
		adminRouter.POST("course/del", adminYoga.Course.Del)

		// 瑜伽小程序-首页
		adminRouter.POST("home/save", adminYoga.Home.Save)
		adminRouter.POST("home/list", adminYoga.Home.List)
		adminRouter.POST("home/info", adminYoga.Home.Info)
		adminRouter.POST("home/del", adminYoga.Home.Del)
		adminRouter.POST("home/search", adminYoga.Home.Search)

		// 瑜伽小程序-配置
		adminRouter.POST("config/save", adminYoga.Config.Save)
		adminRouter.POST("config/list", adminYoga.Config.List)
		adminRouter.POST("config/info", adminYoga.Config.Info)
		adminRouter.POST("config/del", adminYoga.Config.Del)

		//卡券
		adminRouter.POST("carmine/save", admin.Carmine.Save)
		adminRouter.POST("carmine/info", admin.Carmine.Info)
		adminRouter.POST("carmine/list", admin.Carmine.List)
		adminRouter.POST("carmine/del", admin.Carmine.Del)
		adminRouter.POST("carmine/generated_code", admin.Carmine.GeneratedCode)

		// 用户卡券
		adminRouter.POST("user_carmine/list", admin.UserCarmine.List)
		adminRouter.POST("user_carmine/give", admin.UserCarmine.Give)
		adminRouter.POST("user_carmine/bind", admin.UserCarmine.Bind)
		adminRouter.POST("user_carmine/import", admin.UserCarmine.Import)

		// 瑜伽订单
		adminRouter.POST("yoga_order/list", adminYoga.Order.Order)
		adminRouter.POST("yoga_order/course_order", adminYoga.Order.CourseOrder)

		adminRouter.POST("fast_mail/query", admin.FastMail.Query)
		adminRouter.POST("fast_mail/poll", admin.FastMail.Poll)
		adminRouter.POST("fast_mail/coupon_query", admin.FastMail.CouponQuery)
		adminRouter.POST("fast_mail/coupon_poll", admin.FastMail.CouponPoll)

	}
	//大屏看板
	screenbordRouter := r.Group("admin")
	{
		// 授权验证
		screenbordRouter.Use(middleware.Screenbord())
		screenbordRouter.POST("screenboard/goods", admin.Screenboard.Goods)
		screenbordRouter.POST("screenboard/time", admin.Screenboard.Time)
		screenbordRouter.POST("screenboard/line", admin.Screenboard.Line)
		screenbordRouter.POST("screenboard/order", admin.Screenboard.Order)
		screenbordRouter.POST("screenboard/behavior", admin.Screenboard.Behavior)
	}
}
